<?php session_start(); 
if ( $_SESSION["level"] == null ) header("location:login.php");
else if ( $_SESSION["level"] != "admin" ) header("location:index.php");
include 'config.php';
include 'db_connection.php';
?>
<!DOCTYPE html>
<html>
 <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <link rel="shortcut icon" href="./files/img/favicon.ico">
  <title>IAD - Euromedica</title>

  <link type="text/css" href="./files/jquery-ui/css/smoothness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />	
  <script type="text/javascript" src="./files/jquery-1.6.4.js"></script>
  <script type="text/javascript" src="./files/jquery-ui/js/jquery-ui-1.8.16.custom.min.js"></script>

  <style type="text/css">
    @import "style2.css";
  </style>

  <script type="text/javascript" src="./scripts.js"></script>
</head>
 <?php 
   include 'sql.php';
 ?>

<body>

<div id="access">
  <p><a href="./index.php">Home</a></p>  
  <?php if (isset($_SESSION["user"])) { ?>
    <?php if ($_SESSION["level"] == "admin") {?><p><a href="./admin.php">Administer</a></p>
    <?php } else { ?><p><a href="./index.php">Administer</a></p><?php } ?>
  <?php } else { ?><p><a href="./register.php">Not Registered Yet?</a></p><?php } ?>
  <?php if (isset($_SESSION["user"])) {?><p><a href="./logout.php">Logout</a></p>
  <?php } else { ?><p><a href="./login.php">Login</a></p><?php } ?> 
</div> <!--End of access-->

  <!--
  Start Header Area
  -->
<div id="header">
</div><!-- End of HEADER -->

<div id="ribbon">
  <table>
    <tr>

    </tr>
  </table>
</div><!--End of ribbon-->

 <!--
  Start Left Panel Area
  -->
 <?php showLeftPanel($_SESSION['level'], $_SESSION['user']); ?>
    <!--
    End of Left_panel
    -->

 <!--
  Start Container Area
  -->
 <div id="container">
  <div id="content"><!-- Content Area-->
    <div id="form" style="margin-top: 10px;">
      <form action="convert2MySQL.php" method="post">
	<textarea name="requests_array" rows="20" cols="109"></textarea><br>
	  <select name="status">
	    <option value="approved" label="approved">Approved</option>
	    <option value="rejected" label="rejected">Rejected</option>
	    <option value="pending" label="pending">Pending</option>
	    <option value="ready" label="ready">Ready for approval</option>
	    <option value="misc" label="misc">Misc</option>
	</select>
	<input type="submit" name="Insert" value="Insert">
      </form>
    </div><!--End of form-->
  </div><!--END of content-->
</div><!--END of container-->

<?php showFooter(); ?><!--END of footer-->

<!-- Team Info -->
<script>
$(document).ready(function(){
  $(".edit_team").click(function(){
    var ID = $(this).attr('id');
    $("#team-"+ID).hide();
    $("#edra-"+ID).hide();
    $("#address-"+ID).hide();
    $("#president-"+ID).hide();
    $("#coach-"+ID).hide();
    $("#league-"+ID).hide();
    $("#year-"+ID).hide();
    $("#team-input-"+ID).show();
    $("#edra-input-"+ID).show();
    $("#address-input-"+ID).show();
    $("#president-input-"+ID).show();
    $("#coach-input-"+ID).show();
    $("#league-input-"+ID).show();
    $("#year-input-"+ID).show();
    }).change(function() {
      var ID=$(this).attr('id');
      var team = $("#team-input-"+ID).val();
      var edra = $("#edra-input-"+ID).val();
      var address = $("#address-input-"+ID).val();
      var president = $("#president-input-"+ID).val();
      var coach = $("#coach-input-"+ID).val();
      var league = $("#league-input-"+ID).val();
      var year = $("#year-input-"+ID).val();

      var dataString = 'team_id='+ ID +'&team_name='+team+'&team_edra='+edra+'&team_address='+address+'&teeditam_president='+president+'&team_coach='+coach+'&league='+league+'&year_est='+year;
//       $("#score-"+ID).html('<img src="load.gif" />'); // Loading image
   
      if(team.length>0 && edra.length>0 && address.length>0 && president.length>0 && coach.length>0 && league.length>0 && year.length>0) {
// alert(dataString);
	$.ajax({
	  type: "POST",
	  url: "sql.php",
	  data: dataString,
	  cache: false,
	  success: function(html) {
 	    $("#team-"+ID).html(team);
 	    $("#edra-"+ID).html(edra);
 	    $("#address-"+ID).html(address);
 	    $("#president-"+ID).html(president);
 	    $("#coach-"+ID).html(coach);
 	    $("#league-"+ID).html(league);
 	    $("#year-"+ID).html(year);
	  }
	});
      }//end of if
      else { alert('Enter something.');}
      });

    $(".editbox").mouseup(function() {
      return false;
    }); // end of mouseup
    // Outside click action
    $(document).mouseup(function() {
      $(".editbox").hide();
      $(".text").show();
    }); // end of mouseup
    $(document).hover(function(){
      var ID=$(this).attr('id');
      $("#edit-"+ID).hide();
      $("#delete-"+ID).hide();
    });//end of hover
    $(".editbox").keydown(function(event) {
      if (event.which == 13){
	//$(".editbox").hide();
	//$("#edit-"+id).hide();
	//$("#delete-"+id).hide();
	//$(".text").show();
      }//end of if
    }); //end of keydown
});
</script>

<!-- Upload a Video -->
<script>
$(document).ready(function() {
  $(".upload").click(function() {
      var ID = $(".upload").attr('id');

      $("#dialog:ui-dialog").dialog("destroy");
      $("#dialog-upload").dialog({
	title: "Type in the url",
	resizable: false,
	height:200,
	width:400,
	modal: true,
	buttons: {
	  "OK": function() {
	    var vid_url = $("#url").val();
 	    var vid_array = vid_url.split('=');
	    var temp = 'http://www.youtube.com/embed/'+vid_array[1];
	    var dataString = 'vid_url='+vid_array[1]+'&program_id='+ID;
// 	    $("#vid").attr('src', vid_url);
	    $("#vid").attr('src', temp);
	    $.ajax({
	      type: "POST",
	      url: "sql.php",
	      data: dataString,
	      cache: false,
	      success: function(html) {
	      }
	    });
	    $(this).dialog("close");
// alert(vid_url.val());
	  },
	  Cancel: function() {
	    $(this).dialog("close");
	  }//end of Cancel
	}//end of buttons
      });
  });
});
</script>

<!-- Delete all players -->
<script>
$(document).ready(function(){
  $("#check").click(function(){
  var team_name = $(".team_name").attr('id');
  var f = false;
    $( "#dialog:ui-dialog" ).dialog( "destroy" );
      $( "#dialog-confirm" ).dialog({
	title: "Delete all players?",
	resizable: false,
	height:200,
	modal: true,
	buttons: {
	  "Delete all items": function() {
	    f = true;
	    $(this).dialog("close");
	    $(".edit_tr").each(function(index){
	      var id = $(this).attr('id');
	      $(this).hide();
	    });
	    // disable the delete all button
	    $("#check").attr('disabled', 'disabled');
	    if(f == true) {
	      // TO DO -> change it back to del_team_name
	      var dataString = 'del_team_name2='+team_name;
	      $.ajax({
	      type: "POST",
	      url: "sql.php",
	      data: dataString,
	      cache: false,
	      success: function(html) {
	      }

	    });
	    }//end of if
	  },
	  Cancel: function() {
	    f = false;
	    $(this).dialog("close");
	  }//end of Cancel
	}//end of buttons
      });
  });
});
</script>

<script>
$(document).ready(function(){
  var flag = false;
  $(".edit_tr").hover(
    function(){
      var id = $(this).attr('id');
      $("#delete-"+id).show();
      $("#delete-"+id).click(function(){
	flag = true;
	$("#"+id).remove();
       var dataString = 'deli_id='+id;
 
       $.ajax({
 	type: "POST",
 	url: "sql.php",
 	data: dataString,
 	cache: false,
 	success: function(html) {
 	}
       });
      });//end of click for #delete
   },
   function(){
    var id = $(this).attr('id');
     flag = false;
     $("#delete-"+id).hide();
  });//end of hover

$(".edit_tr").click(function() {
  if (flag == false) {
    var ID=$(this).attr('id');
    $("#outfit_number-"+ID).hide();
    $("#player_name-"+ID).hide();
    $("#position_name-"+ID).hide();
    $("#birth_date-"+ID).hide();
    $("#country-"+ID).hide();
    $("#total_games-"+ID).hide();
    $("#total_goals-"+ID).hide();
    $("#total_assists-"+ID).hide();
    $("#total_yellow-"+ID).hide();
    $("#total_red-"+ID).hide();
    $("#total_sent_offs-"+ID).hide();
    $("#total_time-"+ID).hide();
    $("#outfit_number-input-"+ID).show();
    $("#player_name-input-"+ID).show();
    $("#position_name-input-"+ID).show();
    $("#birth_date-input-"+ID).show();
    $("#country-input-"+ID).show();
    $("#total_games-input-"+ID).show();
    $("#total_goals-input-"+ID).show();
    $("#total_assists-input-"+ID).show();
    $("#total_yellow-input-"+ID).show();
    $("#total_red-input-"+ID).show();
    $("#total_sent_offs-input-"+ID).show();
    $("#total_time-input-"+ID).show();
//------------------------------------------------
}//end of if
//--------------------------------------------
    }).change(function() {
      var ID=$(this).attr('id');
      var outfit_number=$("#outfit_number-input-"+ID).val();
      var player_name=$("#player_name-input-"+ID).val();
      var position_name=$("#position_name-input-"+ID).val();
      var birth_date=$("#birth_date-input-"+ID).val();
      var country=$("#country-input-"+ID).val();
      var total_games=$("#total_games-input-"+ID).val();
      var total_goals=$("#total_goals-input-"+ID).val();
      var total_assists=$("#total_assists-input-"+ID).val();
      var total_yellow=$("#total_yellow-input-"+ID).val();
      var total_red=$("#total_red-input-"+ID).val();
      var total_sent_offs=$("#total_sent_offs-input-"+ID).val();
      var total_time=$("#total_time-input-"+ID).val();

      var dataString = 'id='+ ID +'&score='+score+'&date='+dates+'&tickets='+tickets;
      $("#score-"+ID).html('<img src="load.gif" />'); // Loading image
   
      if(score.length>0 && dates.length>0 && tickets.length>0) {
	$.ajax({
	  type: "POST",
	  url: "sql.php",
	  data: dataString,
	  cache: false,
	  success: function(html) {
	    $("#score-"+ID).html(score);
	    $("#date-"+ID).html(dates);
	    $("#tickets-"+ID).html(tickets);
	  }
	});
      }//end of if
      else { alert('Enter something.');}
      });
  // Edit input box click action
  $(".editbox").mouseup(function() {
    return false;
  }); // end of mouseup
  // Outside click action
  $(document).mouseup(function() {
    $(".editbox").hide();
    $(".text").show();
  }); // end of mouseup
  $(document).hover(function(){
    var ID=$(this).attr('id');
    $("#edit-"+ID).hide();
    $("#delete-"+ID).hide();
  });//end of hover
  $(".editbox").keydown(function(event) {
    if (event.which == 13){
      //$(".editbox").hide();
      //$("#edit-"+id).hide();
      //$("#delete-"+id).hide();
      //$(".text").show();
    }//end of if
  }); //end of keydown
});//end of ready
</script>
</body>
</html>